<template>
  <div class="main">
    <l-panel style="padding-left: 0" class="nobg">
      <template #toolLeft>
        <div class="l-panel--item">
          <el-input
            :placeholder="$t('please enter编码/名称')"
            @keyup.enter.native="hanleSearch"
            v-model="searchWord"
            size="mini"
          >
            <el-button
              @click="hanleSearch"
              slot="append"
              icon="el-icon-search"
            ></el-button>
          </el-input>
        </div>
      </template>
      <div
        class="l-rblock"
        style="padding-bottom: 48px; background: #fff"
        v-loading="tableLoading"
      >
        <div class="l-rblock" style="overflow: hidden auto">
          <div class="v-item" v-for="item in tableShowData" :key="item.id">
            <el-image
              v-if="item.id"
              :src="`https://api.qukai3d.com${item.thumbnail}`"
            >
            </el-image>
            <div class="content__main">
              <div class="content_title l_block_ellipsis">
                {{ item.name }}
              </div>
              <div class="content__menulist">
                <el-button @click="handlePreview(item)" style="margin-left: 8px"
                  >Preview</el-button
                >
              </div>
            </div>
          </div>
        </div>
      </div>
    </l-panel>
  </div>
</template>

<script>
const api = window.$api.demo.threeD;
export default {
  data() {
    return {
      value: "",
      tableLoading: false,
      tableData: [],
      tableShowData: [],
      searchWord: "",
    };
  },
  async created() {
    let data2 = {
      UserName: "15823567989",
      Password: "Hcm@123456",
      ClientId: "learun",
      clientSecret: "3txYPz9U1kzl",
      GrantType: "password",
    };
    let AccessToken = await api.getAccessToken(data2);
    let list = await api.getList(this.token, AccessToken.data.accessToken);
    this.tableData = list.data.items;
    this.tableShowData = this.tableData;
    this.loadTablePageData();
  },
  methods: {
    hanleSearch() {
      this.loadTablePageData();
    },
    loadTablePageData() {
      this.tableLoading = true;
      this.tableShowData = this.tableData.filter(
        (item) => item.name.indexOf(this.searchWord) != -1
      );
      this.tableLoading = false;
    },
    handlePreview(item) {
      let routeUrl = this.$router.resolve({
        path: `/demo/3dDisplay/preview3D?id=${item.id}`,
      });
      window.open(routeUrl.href, "_blank");
    },
  },
};
</script>
<style lang="scss">
.v-item {
  position: relative;
  margin: 16px;
  width: 360px;
  height: 280px;
  overflow: hidden;
  border: 0;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  float: left;
  background: #ffffff;
  box-shadow: 0px 0px 8px 2px rgba(0, 0, 0, 0.1);
  border-radius: 4px;

  .el-image {
    position: relative;
    height: 210px;
    width: 100%;
  }

  .content__main {
    width: 100%;
    height: 70px;
    display: flex;
    align-items: center;
    position: absolute;
    left: 0;
    bottom: 0px;
    justify-content: space-between;
    background: #fff;
    box-sizing: border-box;
    padding: 0 16px;
    font-size: 14px;
    color: #333333;
    letter-spacing: 0;
    font-family: AlibabaPuHuiTi-Regular;
    font-weight: 400;
  }
  .content_title {
    width: 170px;
  }
  .content__menulist {
    display: flex;
    i {
      margin-right: 10px;
      cursor: pointer;
    }
    .el-button {
      font-size: 12px;
      padding: 10px 16px;
      margin-left: 16px;
    }
  }
}
.l_block_ellipsis {
  display: inline-block;
  width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-decoration: none;
}
</style>